package com.eduagent.xwqeduagent.app.RoutingStudentAgent;

import cn.hutool.core.map.MapUtil;
import com.eduagent.xwqeduagent.app.RoutingStudentAgent.enums.AgentTypeEnum;
import com.eduagent.xwqeduagent.app.RoutingStudentAgent.prompt.addAgentSystemPrompt;
import com.eduagent.xwqeduagent.constant.Constant;
import com.eduagent.xwqeduagent.openFeign.client.AdminClient;
import com.eduagent.xwqeduagent.openFeign.entity.UserAndRole;
import com.eduagent.xwqeduagent.openFeign.result.Result;
import com.eduagent.xwqeduagent.tools.studenttools.OrderTools;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RequiredArgsConstructor
public class BuyAgent extends AbstractAgent {

    @Resource
    private AdminClient adminClient;

    private final addAgentSystemPrompt addAgentSystemPrompt;
    private final OrderTools orderTools;

    @Override
    public String systemMessage() {
        return com.eduagent.xwqeduagent.app.RoutingStudentAgent.prompt.addAgentSystemPrompt.SYSTEM_PROMPT;
    }

    @Override
    public AgentTypeEnum getAgentType() {
        return AgentTypeEnum.BUY;
    }

    @Override
    public Object[] tools() {
        return new Object[]{orderTools};
    }

    @Override
    public Map<String, Object> toolContext(String sessionId, String requestId) {
        //获取当前登录用户
        Result<UserAndRole> result = adminClient.getById();
        if (result == null || result.getData() == null) {
            throw new RuntimeException("获取用户信息失败");
        }
        UserAndRole userAndRole = result.getData();
        String userId = userAndRole.getId();
        //String userId转Long
        Long userIdLong = Long.parseLong(userId);
        return MapUtil.<String, Object>builder() // 设置tool列表
                .put(Constant.USER_ID, userIdLong) // 设置用户id参数
                .put(Constant.REQUEST_ID, requestId) // 设置请求id参数
                .build();
    }
}
